#import <Cocoa/Cocoa.h>

typedef struct {
    int x;
    int y;
} BWGrid_Square;

typedef enum {
    kTrackDiamonds,
    kTrackIntersections
} BWDiamondCanvas_TrackStyle;


@class BWQueenStitchSet;
@class BWFrenchKnotSet;

@interface BWDiamondCanvas : NSView
{
    NSAffineTransform *rotator;         // rotated -> view
    NSAffineTransform *inverseRotator;  // view -> rotated conversion

    BWQueenStitchSet *stitches;
    BWFrenchKnotSet *frenchKnots;

    id delegate;

    BOOL shouldTrack;

    BOOL isSelected;
    BWGrid_Square selectedSquare;

    BOOL showArea;
    BWGrid_Square areaAnchor, areaOpposite;

    NSColor *backgroundColor;

    BWDiamondCanvas_TrackStyle trackMode;

    int zoom;
}

- (BWDiamondCanvas *) initForPrintingWithStitches: (BWQueenStitchSet *) stitches
                                  backgroundColor: (NSColor *) backgroundColor
                                       areaAnchor: (BWGrid_Square) anchor
                                     areaOpposite: (BWGrid_Square) opposite;

- (void) setDelegate: (id) delegate;
- (void) setStitches: (BWQueenStitchSet *) stitches;
- (void) setFrenchKnots: (BWFrenchKnotSet *) knots;

- (void) setShouldTrack: (BOOL) shouldTrack;

- (void) selectX: (int) x  y: (int) y;
- (void) unselectAll;

- (void) setOffsetX: (float) x  y: (float) y;

- (void) setShowArea: (BOOL) showArea;
- (void) setAreaAnchor: (BWGrid_Square) start;
- (void) setAreaOpposite: (BWGrid_Square) opposite;

- (BWGrid_Square) areaAnchor;
- (BWGrid_Square) areaOpposite;

- (void) setNeedsDisplayInSquare: (BWGrid_Square) square;
- (void) setNeedsDisplayAtIntersection: (BWGrid_Square) square;

- (void) setBackgroundColor: (NSColor *) color;
- (NSColor *) backgroundColor;

- (void) setZoom: (int) zoomFactor; // 100 == 100%

- (void) setTrackMode: (BWDiamondCanvas_TrackStyle) mode;

@end // BWDiamondCanvas



typedef enum {
    kMouseDown,
    kMouseDragged,
    kMouseUp
} BWDiamondCanvas_SelectMode;

@interface NSObject (BWDiamondCanvasDelegate)

- (void) canvas: (BWDiamondCanvas *) canvas  selectionAtX: (int) x
              y: (int) y
           mode: (BWDiamondCanvas_SelectMode) mode;

- (void) canvas: (BWDiamondCanvas *) canvas
      scrolledX: (int) horizontalDelta
              y: (int) verticalDelta;
    

@end // BWDiamondCanvasDelegate
